home *** CD-ROM | disk | FTP | other *** search
- { Turbo 3.x Compare Strings Function
- Copyright (C) July 7, 1986 by Mark Brandon [72477,1546]
-
- This function compares 2 string variables and returns a TRUE/FALSE
- condition based upon the comparison operation (LT,EQ,GT). The
- comparison is performed using the uppercase of the strings; convert
- the two AND AL,$5F to NOPs ($90) if you don't want uppercase con-
- version. Untyped strings are used to allow strings of any length.
- This function is more suited to use in IF statements than the other
- compare strings function that is in DL 1. }
-
- TYPE compare_opcode = (LT,EQ,GT);
- CONST resultable : ARRAY[0..8] OF BOOLEAN = (TRUE,FALSE,FALSE, {LT}
- FALSE,TRUE,FALSE, {EQ}
- FALSE,FALSE,TRUE); {GT}
-
- FUNCTION CompStrs(VAR string1; operation:compare_opcode;
- VAR string2): BOOLEAN;
- BEGIN
- Inline( { inline code created with the INLINE Assembler }
- $1E { PUSH DS}
- /$C4/$76/<STRING1 { LES SI,<string1[BP]}
- /$26/$AC { ES: LODSB}
- /$89/$F7 { MOV DI,SI ; ES:DI = string 1}
- /$88/$C2 { MOV DL,AL ; DL = LENGTH(string1)}
- /$C5/$76/<STRING2 { LDS SI,<string2[BP] ; DS:SI = string 2}
- /$AC { LODSB}
- /$88/$C6 { MOV DH,AL ; DH = LENGTH(string2)}
- /$8A/$5E/<OPERATION { MOV BL,<operation[BP]}
- /$30/$FF { XOR BH,BH ; BX = operation code}
- /$08/$D2 { OR DL,DL}
- /$74/$2C { JZ Null ; jump if string1 = ''}
- /$08/$F6 { OR DH,DH}
- /$74/$23 { JZ Result2 ; jump if string2 = ''}
- /$88/$D1 { MOV CL,DL}
- /$38/$F2 { CMP DL,DH}
- /$72/$02 { JB C1}
- /$88/$F1 { MOV CL,DH}
- /$88/$FD {C1: MOV CH,BH ; CX = shorter of DL or DH}
- /$AC {CmpLoop: LODSB}
- /$24/$5F { AND AL,$5F}
- /$88/$C4 { MOV AH,AL ; AH = UPPER(string2[SI])}
- /$26/$8A/$05 { ES: MOV AL,[DI]}
- /$24/$5F { AND AL,$5F ; AL = UPPER(string1[DI])}
- /$38/$E0 { CMP AL,AH}
- /$72/$17 { JB Result0 ; jump if string1 < string2}
- /$77/$09 { JA Result2 ; jump if string1 > string2}
- /$47 { INC DI}
- /$E2/$ED { LOOP CmpLoop}
- /$38/$F2 { CMP DL,DH}
- /$72/$0E { JB Result0}
- /$74/$09 { JE Result1}
- /$80/$C3/$06 {Result2: ADD BL,6}
- /$EB/$07 { JMP short Result0}
- /$08/$F6 {Null: OR DH,DH}
- /$75/$03 { JNZ Result0}
- /$80/$C3/$03 {Result1: ADD BL,3}
- /$2E/$8A/$87/>RESULTABLE {Result0: CS:MOV AL,>Resultable[BX]; get function result}
- /$88/$46/$0E { MOV [BP+14],AL}
- /$1F) { POP DS}
- function result}
- /$88/$46/$0E { MOV [BP+14],AL}
-